import java.util.ArrayList;
import java.util.List;

import javax.swing.*;

public abstract class myThread implements Runnable
{
	MyJFrame f;
	JTextArea output;
	ArrayList<JComponent> comp=null;
	List<Boolean> btnsStates;
	
	public myThread(MyJFrame f,JTextArea output,ArrayList<JComponent> comp)
	{
		this.f=f;
		this.output=output;
		this.comp=comp;	
		btnsStates=new ArrayList<Boolean>();
	}
	
	public myThread(MyJFrame f,JTextArea output)
	{
		this.f=f;
		this.output=output;
		btnsStates=new ArrayList<Boolean>();
	}
	
	public void run()
	{
		while (f.lock)
		{
			try {
				Thread.sleep(500);
			} catch (InterruptedException e)
			{
				Log.writeEx(e);
			}
		}
		disableButtons();
		if (!body())
			output.append("An error has occoured. please See log file");
		enableButtons();
	}
	
	public void enableButtons()
	{
		if (comp==null)
			return;
		for (int i=0;i<comp.size();i++)
			comp.get(i).setEnabled(btnsStates.get(i));
	}
	
	public void disableButtons()
	{
		if (comp==null)
			return;
		for (JComponent c:comp)
		{
			btnsStates.add(c.isEnabled());
			c.setEnabled(false);
		}
	}

	abstract public boolean body();
}
